#ifndef VISUAL_H
#define VISUAL_H

#include "ui_visual.h"
#include <QDomDocument>
#include <QtGui>
#include <QtCore>

#ifdef _DEBUG
   #ifndef DBG_NEW
      #define DBG_NEW new ( _NORMAL_BLOCK , __FILE__ , __LINE__ )
      #define new DBG_NEW
   #endif
#endif

 class Pixmap : public QObject, public QGraphicsPixmapItem
 {
     Q_OBJECT
     Q_PROPERTY(QPointF pos READ pos WRITE setPos)
 public:
     Pixmap(const QPixmap &pix):QObject(), QGraphicsPixmapItem(pix)
     {setCacheMode(DeviceCoordinateCache);}
 };

 class Line : public QObject, public QGraphicsLineItem
 {
	 Q_OBJECT
	 Q_PROPERTY(QLineF line READ line WRITE setLine)
 public:
	 Line(const QLineF &pix):QObject(), QGraphicsLineItem(pix)
     {setCacheMode(DeviceCoordinateCache);}
 };

 struct takenObject
 {
	Pixmap *item;
	QGraphicsTextItem *num;
	int numberShelf;
	int material;
	int number;
 };
 struct object
 {
	 Pixmap *item;
	 QGraphicsTextItem *num;
 };

 struct settings
 {
	 bool anim;
	 bool log;
	 bool code;
 };
class visual : public QMainWindow
{
	Q_OBJECT

public:
	visual(QWidget *parent = 0, Qt::WFlags flags = 0);
	~visual();

	struct settings options;
	int flagType;

private:
	Ui::visualClass ui;

	int ind;
	int step;
	int currentLine;
	int maxWidth,maxHeight,maxShelf;
	int duration;
	Pixmap *item;
	Pixmap *crane;
	Pixmap *carriage;
	Pixmap *clinch;
	Pixmap *foreman;
	Line *itemLine;
	QGraphicsTextItem *txt;
	QGraphicsScene *scene;
	QDomElement rootAction,child;
	QDomDocument dataFile;
	QList < QPropertyAnimation *> listAnimationCarriage;
	QList < QPropertyAnimation *> listAnimationClinch;
	QList < QPropertyAnimation *> listAnimationCable;
	QList < QPropertyAnimation *> listAnimationObject;
	QList < QPropertyAnimation *> listAnimationNumber;
	QList < QPropertyAnimation *> listAnimationForeman;
	QList < QList < QPropertyAnimation *>> listAnimationShelf;
	QList < QList < object > > itemsList;
	QList < takenObject > itemsTaken;
	QList < bool > shelfs;
	QList < Pixmap *> pointerItem;
	QList < QGraphicsTextItem *> pointerText;
	QMap < int, QDomElement > conditionList;
	QTimer *timer,*timer2;
	QGraphicsLineItem *line1,*line2,*line3,*line4;
	QGraphicsLineItem *line11,*line21,*line31,*line41;

	void setUp(void);
	void changeModeLabel0(void);
	void changeModeLabel1(void);
	void startStep(void);
	void addObject(void);
	void removeObject(void);
	QString avalibleMaterial(QString &str);
	QString avalibleArticle(QString &str);
	void printLog(QString str);
	void processingErrors0();
	void processingErrors1();
	void setStartValue(void);
	int	hasInTakenObjects(void);
	void addShelf(void);
	void selection(void);
	void setPosAnim(QPropertyAnimation * anim,QPointF start,QPointF end);
	void setLineAnim(QPropertyAnimation * anim,QLineF start,QLineF end);
	void changeCurrentLine(void);
	void reAddObject(void);
	void reRemoveObject(void);
	int reHasInTakenObjects(void);
	void setCondition(void);
	int getIndexShelf(void);
	void addObjectError(void);
	void selectionObjectError(void);
	void removeObjectError(void);
	void destructLineError(void);
	void addGhostError(void);
	void setBorder();

private slots:
	void openData(void);
	void blocButton(void);
	void stepForward(void);
	void stepBack(void);
	void run(void);
	void stop(void);
	void disconnectAdd(void);
	void disconnectRemove(void);
	void disconnectDestruct(void);
	void disconnectGhost(void);
	void disconnectAddError(void);
	void disconnectRemoveError(void);
	void selectionEnd(void);
	void durationChanged(int x);
	void optionDialogGet();
	void choiceDialogGet();
	void notationDialogGet();
	void aboutDialogGet();
};

#endif // VISUAL_H
